﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;

namespace Data.Infrastructure
{
    public class DatabaseFactory : Disposable, IDatabaseFactory
    {
        private DbEntityContext dataContext;

        public DbEntityContext Get()
        {
            //如果希望更新Entity后，自动更新数据库。注意，数据将丢失
            //Database.SetInitializer(new DropCreateDatabaseIfModelChanges<DbEntityContext>());
            return dataContext ?? (dataContext = new DbEntityContext());
        }

        protected override void DisposeCore()
        {
            if (dataContext != null)
                dataContext.Dispose();
        }
    }
}
